home *** CD-ROM | disk | FTP | other *** search
/ IRIX 6.4 Applications 1997 August / SGI IRIX 6.4 Applications 1997 August.iso / dist / gateway.idb / usr / WebFace / Source / 20-NetworkServices / routing / mrouted.frm.z / mrouted.frm
Encoding:
Text File  |  1997-07-30  |  6.3 KB  |  249 lines

  1. #!/usr/bin/perl5
  2. #
  3. # mrouted.cgi
  4. #
  5. # Copyright 1988-1996 Silicon Graphics, Inc.
  6. # All rights reserved.
  7. #
  8. # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  9. # the contents of this file may not be disclosed to third parties, copied or
  10. # duplicated in any form, in whole or in part, without the prior written
  11. # permission of Silicon Graphics, Inc.
  12. #
  13. # RESTRICTED RIGHTS LEGEND:
  14. # Use, duplication or disclosure by the Government is subject to restrictions
  15. # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  16. # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  17. # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  18. # rights reserved under the Copyright Laws of the United States.
  19. #
  20. # $Id: mrouted.frm,v 1.30 1997/06/19 22:26:26 shotes Exp $
  21.  
  22. require "/usr/OnRamp/lib/OnRamp.pm";
  23. require "/usr/OnRamp/lib/java.pm";
  24.  
  25. $conf = "/etc/mrouted.conf";
  26. $options = "/etc/config/mrouted.options";
  27. $dummy = "/etc/mrouted.conf.tmp";
  28. $data = "/etc/mrouted.conf.data";
  29. $myname = "mrouted.cgi";
  30. $title = "Multicast Routing";
  31.  
  32. if ($ENV{'HTTP_USER_AGENT'} =~ /Mozilla\/2/) { $br_index = 1; }
  33. else { $br_index = 0; }
  34.  
  35. $js =
  36. "br_index = $br_index;
  37. $js_standard
  38. $js_error_box
  39. $js_ip
  40. function checkForm(form)  {
  41.     if (form.emr[br_index].checked && form.tun[br_index].checked) { // radio buttons are backwards
  42.         if (!testAddress(form.rip)) return (false);
  43.     }
  44.     return (true);
  45. }
  46. function testAddress(Ctrl) {
  47.     if (Ctrl.value == \"\") { 
  48.         errorBox (Ctrl, \"The remote IP address is required.\"); 
  49.         return (false); 
  50.     }
  51.     if (!testIPaddress(Ctrl.value,false)) { 
  52.         errorBox (Ctrl, \"The remote IP address \" + Ctrl.value 
  53.             + \" \\nis invalid.\"); 
  54.         return (false); 
  55.     }
  56.     return (true);
  57. }";
  58.  
  59. print "Content-type: text/html\n\n";
  60.  
  61. &get_fields;
  62.  
  63. &getInfo;
  64.  
  65. $help = $document_root . $ENV{"SCRIPT_NAME"};
  66. $help =~ s/cgi$/hlp/;
  67. exec $help if ($fld{'help'} eq "Help");
  68.  
  69. if ($fld{"doit"} eq "Ok") { 
  70.     if ($fld{'tun'} eq 'Yes' && $fld{'emr'} eq 'Yes') { &formValidation; }
  71.     &edit; 
  72.     &getInfo; 
  73. }
  74.  
  75. if (-e "/usr/etc/mrouted") { &generic; }
  76. else { 
  77.     &title_block($title);
  78.     &header_block($title);
  79.     print "<i>Multicast routing software not installed.  Install
  80.         subsystem </i><b>eoe.sw.ipgate</b><i> from the distribution CD.</i>";
  81. }
  82.  
  83. sub error {
  84.     &error_block($_[0]);
  85.     %val = %fld;
  86.     &generic;
  87.     exit 0;
  88. }
  89.  
  90. sub edit {
  91.     system("/etc/killall", "mrouted");
  92.     if ($fld{'emr'} eq 'Yes') {
  93.     if ($val{'emr'} eq 'No') { $message = "Multicast routing enabled.  "; }
  94.     if ($fld{'tun'} eq 'Yes') { 
  95.         &writeTunnel;
  96.         $message .= "Tunnel information updated.";
  97.     }
  98.     else { 
  99.         &turnOffTunnel;
  100.         $message .= "Tunnel disabled."; 
  101.     }
  102.     &restartDeamon("mrouted","/usr/etc/mrouted",$options);
  103.     system("/etc/chkconfig", "mrouted", "on");
  104.     } else { 
  105.     system("/etc/chkconfig", "mrouted", "off");
  106.     if ($val{'emr'} eq 'Yes') { 
  107.         $message = "Multicast routing disabled.";
  108.     } else { $message = "No change made."; }
  109.     $val{'emr'} = "No";
  110.     }
  111. }
  112.  
  113. sub turnOffTunnel {
  114.     ($dummy,$local) = split(/ /,$fld{'int'});
  115.  
  116.     open(IN,"< $conf");
  117.     open(OUT,"> $dummy");
  118.     while(<IN>) {
  119.     $line = $_;
  120.     @items = split(/\s+/,$line);
  121.     if ($items[0] eq "tunnel"  && $items[1] eq $local) { 
  122.         $line = "# $line"; 
  123.     }
  124.     print OUT $line;
  125.     }
  126.     close(IN);
  127.     close(OUT);
  128.     rename($dummy,$conf);
  129. }    
  130.  
  131. sub writeTunnel {
  132.     ($skip,$local) = split(/ /,$fld{'int'});
  133.  
  134.     open(IN,"< $conf");
  135.     open(OUT,"> $dummy");
  136.     $printed = 0;
  137.     while(<IN>) {
  138.     @items = split(/\s+/);
  139.     if ($items[0] ne "tunnel") { print OUT $_; }
  140.     else {
  141.         if ($items[1] eq $local) {
  142.         if ($items[2] eq $fld{'rip'}) {
  143.             print OUT $_;
  144.             $printed = 1;
  145.         } else {
  146.             print OUT "# $_";
  147.             print OUT "tunnel $local $fld{'rip'}\n";
  148.             $printed = 1;
  149.         }
  150.         } 
  151.     }
  152.     }
  153.     if (!$printed) { print OUT "tunnel $local $fld{'rip'}\n"; }
  154.     close(OUT);
  155.     close(IN);
  156.     rename($dummy,$conf);
  157. }
  158.  
  159. sub restartDeamon {
  160.     $command = "$_[1] ";
  161.     open(IN,"< $_[2]");
  162.     while(<IN>) { chop($_); $command .= " $_"; }
  163.     close(IN);
  164.     system($command);
  165. }
  166.  
  167. sub formValidation {
  168.     &error("Remote IP address required.") if $fld{'rip'} eq "";
  169.     if (&check_ipaddr($fld{'rip'})) {
  170.         &error("Invalid remote IP address");
  171.         &generic;
  172.         exit 0;
  173.     }
  174. }
  175.    
  176. sub generic {
  177.     &js_title_block($title,$js);
  178.     &header_block($title);
  179.  
  180.     print "<i>$message</i>";
  181.  
  182.     print qq|<form method=post name="StandardForm" action="$myname" onSubmit="return runSubmit()">|;
  183.  
  184.     print "<center><table cellpadding=5 width=450>";
  185.  
  186.     print "<tr><th align=left>Enable multicast routing:</th><th align=left>",
  187.       &radio('emr',$val{'emr'},"Yes","No"), "</th></tr><tr></tr>";
  188.  
  189.     print "<tr><th align=left>Setup IP tunnel (if needed):</th><th></th></tr>";
  190.  
  191.     print "</table>";
  192.  
  193.     print '<table cellpadding=5 width=350>';
  194.  
  195.     print '<tr><th align=left>Enable tunnel:</th>',
  196.       '<td align=left><strong>';
  197.     print &radio('tun',$val{'tun'},"Yes","No");
  198.     print '</strong></td></tr>';
  199.     print '<tr><th align=left>Interface:</th><td align=left>';
  200.     print qq|<select name="int">|;
  201.     for ($i=0;$i<=$#myInt;$i++) {
  202.     if ($locIP ne $myIP[$i]) { print "<option>$myInt[$i] $myIP[$i]"; }
  203.     else { print "<option selected>$myInt[$i] $myIP[$i]"; }
  204.     }
  205.     print "</select>";
  206.     print '</td></tr><tr><th align=left>Remote IP address:</th><td align=left>';
  207.     print &text('rip',$val{'rip'},14);
  208.     print '</td></tr>';
  209.     print '</table><br>';
  210.  
  211.     print &js_buttons('doit','Ok','onClick="markOK()"','onClick="markOther()"');
  212.  
  213.     print '</form>';
  214. }
  215.  
  216. sub getInfo {
  217.     undef @myInt;
  218.     undef @myIP;
  219.     open(IN, "/usr/OnRamp/bin/htnetwork |");
  220.     while(<IN>) {
  221.     @items = split(/:/);
  222.     if ($items[3]) {
  223.         push(@myInt,$items[1]);
  224.         push(@myIP,$items[3]);
  225.     }
  226.     }
  227.     close(IN);
  228.  
  229.     $val{'rip'} = "";
  230.     $met = 1;
  231.     $val{'tun'} = "No";
  232.  
  233.     $val{'emr'} = &get_config("mrouted");
  234.  
  235.     open(IN,"< $conf");
  236.     while(<IN>) {
  237.     @items = split(/\s+/);
  238.     if ($items[0] ne 'tunnel') { next; }
  239.     for($i=0;$i<=$#myIP;$i++) {
  240.         if ($myIP[$i] eq $items[1]) {
  241.         $val{'rip'} = $items[2];
  242.         $locIP = $myIP[$i];
  243.         $val{'tun'} = "Yes";
  244.         }
  245.     }
  246.     }
  247.     close(IN); 
  248. }
  249.